package com.dempsey.voronoiweb.project.entity;
import lombok.Data;

/**
 * The type Line.
 * @author fengyuan
 */
@Data
public class Line {
    private Point p1;
    private Point p2;
    private double k;
    private double b;

    /**
     * Instantiates a new Line.
     *
     * @param p1 the p 1
     * @param p2 the p 2
     */
    public Line(Point p1, Point p2) {
        this.p1 = p1;
        this.p2 = p2;
        createLineWithTwoPoints(this);
    }

    private void createLineWithTwoPoints(Line line) {
        double x1, x2, y1, y2;
        x1 = p1.getLongitude();
        x2 = p2.getLongitude();
        y1 = p1.getLatitude();
        y2 = p2.getLatitude();
        line.k = (y1 - y2) / (x1 - x2);
        line.b = y1 - (y1 - y2) * x1 / (x1 - x2);
    }

}
